import { http } from "@/utils/http";

export interface DeviceEntranceGuardQuery extends BasePageQuery { // 列表查询参数
  deviceName: string | number;
}

type DeviceEntranceGuardDTO = { // 返回数据
  id: string;
  deviceName: string;
};

export type DeviceEntranceGuardRequest = { // 添加修改请求参数
  id?: number;
};

/** 获取设备管理列表 */
export const getDeviceEntranceGuardListApi = (params?: DeviceEntranceGuardQuery) => {
  return http.request<ResponseData<PageDTO<DeviceEntranceGuardDTO>>>(
    "get",
    "/device",
    {
      params
    }
  );
};

/** 添加设备管理 */
export const addDeviceEntranceGuardApi = (data: DeviceEntranceGuardRequest) => {
  return http.request<ResponseData<void>>("post", "/device", {
    data
  });
};

/** 修改设备管理 */
export const updateDeviceEntranceGuardApi = (data: DeviceEntranceGuardRequest) => {
  return http.request<ResponseData<void>>(
    "put",
    `/device/${data.id}`,
    {
      data
    }
  );
};

/** 删除设备管理 */
export const deleteDeviceEntranceGuardApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/device", {
    params: {
      // 需要将数组转换为字符串  否则Axios会将参数变成 ids[0]:1  ids[1]:2 这种格式，后端接收参数不成功
      ids: data.toString()
    }
  });
};
